home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Sherlock 2.0
/
DevLibSrc
/
Main_DevLib
/
LIBmem.h
< prev
next >
Wrap
Text File
|
1995-11-16
|
4KB
|
151 lines
/*
devlib: memory allocation functions.
source: LIBmem.h
started: September 22, 1993.
version:
November 14, 1995.
Added `mem_free_life_node' and `mem_free_stat_node'.
Added `lib_calloc' and `lib_free'.
May 24, 1994.
Changed mem_stat_bytes to mem_cur_stat_bytes.
Changed mem_stat_nodes to mem_cur_stat_nodes.
April 24, 1994.
Added maximum statistics.
April 6, 1994.
Define mem_life_list here, not in XXmem.h.
April 5, 1994.
*/
#ifndef LIBmem_h_
#define LIBmem_h_
#pragma once
#include <string.h>
/*
Enable or disable local statistics.
*/
#undef DO_MEM_STATS
#define DO_MEM_STATS
#ifdef DO_MEM_STATS
#define MEM_STATS(s) s
#define MEM_UPDATE_STATS(life_stat,size) \
{\
ASSERT(life_stat);\
life_stat -> mem_cur_stat_nodes++;\
life_stat -> mem_cur_stat_bytes += (size);\
}
#else
#define MEM_STATS(s)
#define MEM_UPDATE_STATS(life_stat,size)
#endif
/*
Define the types used by the memory manager.
*/
typedef struct mem_life_struct mem_life;
typedef struct mem_block_struct mem_block;
typedef struct mem_stat_struct mem_stat;
/*
The following structure describes the memory with a given lifetime.
*/
struct mem_life_struct {
/* The name of the lifetime. */
char * mem_life_name;
/* Status variables. */
void * mem_ptr; /* Pointer to the next free byte. */
long mem_avail; /* Number of available bytes in the current block. */
/* Lists. */
mem_life * mem_life_list; /* List of all lifetimes. */
mem_block * mem_block_list; /* List of allocated blocks. */
mem_stat * mem_life_stat_list; /* List of all statistics nodes. */
long mem_last_avail; /* Available bytes in the last allocated block. */
long mem_tot_blocks; /* Total number of normal blocks. */
long mem_tot_nodes; /* Total number of normal nodes. */
long mem_tot_bytes; /* Total number of bytes in normal nodes. */
long mem_tot_waste; /* Total number of unused bytes in normal nodes. */
long mem_tot_big_blocks; /* Total number of normal blocks. */
long mem_tot_big_bytes; /* Total number of bytes in big nodes. */
long mem_cur_blocks; /* Current number of normal blocks. */
long mem_cur_nodes; /* Current number of normal nodes. */
long mem_cur_bytes; /* Current number of bytes in normal nodes. */
long mem_cur_waste; /* Current number of unused bytes in normal nodes. */
long mem_cur_big_blocks; /* Current number of normal blocks. */
long mem_cur_big_bytes; /* Current number of bytes in big nodes. */
long mem_max_blocks; /* Current number of normal blocks. */
long mem_max_nodes; /* Current number of normal nodes. */
long mem_max_bytes; /* Current number of bytes in normal nodes. */
long mem_max_waste; /* Current number of unused bytes in normal nodes. */
long mem_max_big_blocks; /* Current number of normal blocks. */
long mem_max_big_bytes; /* Current number of bytes in big nodes. */
};
struct mem_stat_struct {
TYPE_LIST(mem_stat);
char * mem_stat_node_tag;
long mem_cur_stat_nodes; /* Current statistics. */
long mem_cur_stat_bytes;
long mem_tot_stat_nodes; /* Total statistics. */
long mem_tot_stat_bytes;
long mem_max_stat_nodes; /* Maxima statistics. */
long mem_max_stat_bytes;
};
/*
Normal blocks are allocated in chunks of MEM_BLOCK_SIZE.
*/
#define MEM_BLOCK_SIZE 1024
#define MEM_ALLOC_SIZE (MEM_BLOCK_SIZE-sizeof(mem_block *))
struct mem_block_struct {
TYPE_LIST(mem_block);
char mem_data [MEM_ALLOC_SIZE];
};
/*
Function prototypes.
*/
#define DUMP_CURRENT_STATS TRUE
#define DONT_DUMP_CURRENT_STATS FALSE
void * lib_calloc (size_t, size_t);
void lib_free (void * p);
void mem_compute_max_stats (mem_life * life);
void mem_dump_stats (mem_life * life);
void mem_free_life (mem_life * life);
void mem_free_life_node (register mem_life * life);
void mem_free_stat_node (mem_stat * the_stat);
mem_life * mem_init_life (char * life_name);
mem_stat * mem_init_stats (mem_life * life, char * node_tag);
void * mem_new_big_block (size_t size, mem_life * life, char * dtag);
void * mem_new_block (size_t size, mem_life * life);
char * mem_str_copy (char * start, size_t length);
/*
Variables.
*/
extern mem_life * mem_life_list; /* List of all lifetimes. */
#endif /* LIBmem_h_ */